/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package org.moon.framework.autoconfigure.oss;

import org.moon.framework.autoconfigure.MoonConstants;
import org.moon.framework.autoconfigure.cache.CacheService;
import org.moon.framework.autoconfigure.config.SpringContextConfig;
import org.moon.framework.autoconfigure.exception.domain.MoonException;
import org.moon.framework.autoconfigure.oss.impl.*;
import org.moon.framework.autoconfigure.oss.props.OssProperties;
import org.springframework.context.annotation.Configuration;

/**
 * 对象存储调用入口
 * @author moon
 */
@Configuration
public class OssTemplate {

    public final static String CACHE_OSS_CONFIG = "oss:config";

    /**
     * 获取对象存储操作对象
     */
    public static OssService getOssTemplate(){
        OssService ossService=null;
        CacheService cacheService = SpringContextConfig.getBean(CacheService.class);
        OssProperties ossProperties = cacheService.get(CACHE_OSS_CONFIG, OssProperties.class);
        if(ossProperties==null){
            ossProperties = new OssProperties();
        }
        switch (MoonConstants.OssTypeEnum.valueOf(ossProperties.getName())){
            case local:
                ossService = new LocalOssProviderImpl(ossProperties);
                break;
            case scp:
                ossService = new ScpOssProviderImpl(ossProperties);
                break;
            case minio:
                ossService = new MinioOssProviderImpl(ossProperties);
                break;
            case qiniu:
                ossService = new QiniuOssProviderImpl(ossProperties);
                break;
            case aliyun:
                ossService = new AliOssProviderImpl(ossProperties);
                break;
            default:
                throw new MoonException("暂时不支持的类型");
        }
        return ossService;
    }
}
